/**
 * @author: saz
 * @date 2019/3/30 22:22
 */
package imooc.rabbitmq.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建一个 ConnectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();

        // 设置连接属性
        connectionFactory.setHost("129.211.100.215");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        // 通过连接工厂创建连接
        Connection connection = connectionFactory.newConnection();

        // 通过 connection 创建一个 Channel
        Channel channel = connection.createChannel();

        // 通过 channel 发送数据
        for(int i =0;i<5;i++){
            // 第一个参数
            channel.basicPublish("", "test001",null ,"Hello, RabbitMQ!".getBytes() );
        }

        // 关闭连接
        channel.close();
        connection.close();
    }
}
